

//顶部选项卡切换事件
$('.activ-nav-list').on('click',function(){
    var _this = $(this);
    _this.addClass('activ-nav-add');
    _this.siblings().removeClass('activ-nav-add');
    var top = _this.attr('data-top');
    if(top >= 6){ // 待审核选手

    }else{ // 活动切换
        window.location.href="/admin/activity/listtpl/top_time/"+top;
    }
});


//下拉菜单列表事件
layui.use('form', function(){
    var form = layui.form;
    form.on('select(start_id)', function(data) {
        var start_id = parseInt(data.value);
        var top_time = $('.activ-nav-add').attr('data-top');
        var section = $('.activ-set-time-add').attr('data-section');
        if(section > 1){
            window.location.href="/admin/activity/listtpl?top_time="+top_time+"&start_id="+start_id+"&type_time="+section;
        }
        var time = $('#set-dat-choose').val();
        if(time != ''){
            window.location.href="/admin/activity/listtpl?top_time="+top_time+"&start_id="+start_id+"&button_time="+time;
        }
    });
});


//选择时间按钮事件
$('.activ-set-time-day').on('click',function(){
    var _this = $(this);
    _this.addClass('activ-set-time-add');
    _this.siblings().removeClass('activ-set-time-add');
    var start_id = $('#start_id').val(); // 0为开始时间 1为结束时间
    var top_time = $('.activ-nav-add').attr('data-top');
    var section = $('.activ-set-time-add').attr('data-section');
    window.location.href="/admin/activity/listtpl?top_time="+top_time+"&start_id="+start_id+"&type_time="+section;
});



//日期时间范围
layui.use('laydate', function(){
    var laydate = layui.laydate;
    //执行一个laydate实例
    laydate.render({
        elem:'#set-dat-choose', //指定元素
        type: 'date',
        range: true,
        done: function(value){
            var start_id = $('#start_id').val(); // 0为开始时间 1为结束时间
            var top_time = $('.activ-nav-add').attr('data-top');
            window.location.href="/admin/activity/listtpl?top_time="+top_time+"&start_id="+start_id+"&button_time="+value;
        }
    });
});


//排序箭头
// 复用性
$(document).on('click',".span5,.span6",function(){
    var _this = $(this);
    var obj = _this.parents('li');
    var order = 'desc';
    var filed = 'serial';
    var clas = obj.attr('class');
    if(_this.hasClass('span5')){ // 第一个箭头
        sortAction(_this,'span1');
        if(_this.find('i').hasClass('fa-long-arrow-up')){ // 上
            order = 'asc';
        }
        if(clas == 'li1'){
            filed = 'serial';
        }else if(clas == 'li5'){
            filed = 'competitor_number';
        }else if(clas == 'li6'){
            filed = 'day_vote_num';
        }else if(clas == 'li7'){
            filed = 'day_gift_price';
        }else if(clas == 'li8'){
            filed = 'real_visitor_num';
        }
    }else{ // 第二个箭头
        sortAction(_this,'span3');
        if(_this.find('i').hasClass('fa-long-arrow-up')){ // 上
            order = 'asc';
        }
        if(clas == 'li6'){
            filed = 'vote_num';
        }else if(clas == 'li7'){
            filed = 'gift_price';
        }else if(clas == 'li8'){
            filed = 'visitor_num';
        }
    }
    // 搜索内容
    var keyword = $('.activ-set-seach').find('input').val();
    var start_id = $('#start_id').val(); // 0为开始时间 1为结束时间
    var top_time = $('.activ-nav-add').attr('data-top');
    var section = $('.activ-set-time-add').attr('data-section');
    var time = $('#set-dat-choose').val();
    window.location.href="/admin/activity/listtpl?top_time="+top_time+"&start_id="+start_id+"&type_time="+section+"&keyword="+keyword+"&button_time="+time+"&filed="+filed+"&order="+order;
});

// 自定义排序方法
function sortAction(obj,num) {
    var Chid = obj.children();
    $('.addblock').removeClass('color1');
    obj.removeClass('addblock');
    $('.addblock').children().removeClass('fa-long-arrow-up').addClass('fa-long-arrow-down');

    if(Chid.hasClass('fa-long-arrow-down')){
        Chid.removeClass('fa-long-arrow-down').addClass('fa-long-arrow-up');
    }else{
        Chid.removeClass('fa-long-arrow-up').addClass('fa-long-arrow-down');
    }
    obj.parent().find('.'+num).addClass('color1');
    obj.addClass('color1 addblock');






}



//分页
layui.use('laypage', function(){
    var laypage = layui.laypage;
    laypage.render({
        elem: 'all-activ-page-list',
        count:zcount, //数据总数，从服务端得到
        layout: ['count', 'prev', 'page', 'next', 'skip'],
        theme: '#3aa1ff',
        groups:10,
        limit:1,
        jump: function(obj, first) {
            var p = obj.curr;
            if(p > 1){
                $.ajax({
                    type: 'POST',
                    dataType: 'json',
                    url: "test.php",
                    async: false,
                    data: {"pages":pages},
                    success:function(msg){

                    }
                });
            }
        }
    });
});


// 时间倒计时
$('.end_time').each(function () {
    var _this = $(this);
    var time = _this.data('time');
    getCountDowns(_this.next(),time);
});

// 时间倒计时自定义函数
function getCountDowns(clas,timestamp){
    is_intval = setInterval(function(){
        var nowTime = new Date();
        var endTime = new Date(timestamp * 1000);
        var t = endTime.getTime() - nowTime.getTime();
        var day = parseInt(t / 1000 / 60 / 60 / 24);
        var hour=Math.floor(t/1000/60/60%24);
        var min=Math.floor(t/1000/60%60);
        var sec=Math.floor(t/1000%60);
        if (hour < 10) {
            hour = "0" + hour;
        }
        if (min < 10) {
            min = "0" + min;
        }
        if(sec<0){
            clearInterval(is_intval);
            $(clas).html('计时：0天00时00分00秒');
            return false;
        }
        if (sec < 10) {
            sec = "0" + sec;
        }
        var countDownTime = day+'天'+hour+'时'+min+"分"+sec+'秒';
        $(clas).html('计时：'+countDownTime);
    },1000);
}



// 增加浏览量 add_visitor
$(document).on('click','.add_visitor',function () {
    var _this = $(this);
    var num = _this.prev().val();
    if(num == '' || num == 0){
        layer.msg('请输入大于0的数值');return;
    }
    var visitorObj = _this.parent().prev();
    var zongNum = visitorObj.attr('data-vnum');
        zongNum = parseInt(zongNum) + parseInt(num);
    var id = _this.parents('.ul-top').data('id');
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: "/admin/Activity/visitorAction",
        data: {"num":num,"id":id},
        success:function(msg){   //function1()
            layer.msg(msg.msg);
            if(msg.code == 0){
                visitorObj.html('总：'+zongNum);
                visitorObj.attr("data-vnum",zongNum);
            }
        }

    });
});



function dataReturn(){

}



















